package com.js.myapp.system.activity;

// Created by JS on 2021/7/23.

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.js.baseview.toprightmenu.MenuItem;
import com.js.baseview.toprightmenu.TopRightMenu;
import com.js.basicutils.NavigationBarUtil;
import com.js.basicutils.StatusBarUtil;
import com.js.myapp.R;
import com.js.myapp.databinding.ActivityTopRightMenuBinding;

import java.util.ArrayList;
import java.util.List;

public class TopRightMenuActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {

    private ActivityTopRightMenuBinding binding;

    private boolean showIcon = true;
    private boolean dimBg = true;
    private boolean needAnim = true;

    private TopRightMenu mTopRightMenu;

    public static void start(Context context) {
        Intent intent = new Intent(context, TopRightMenuActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityTopRightMenuBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        StatusBarUtil.setStatusBarColor(this, R.color.color_statusbar_bg);
        NavigationBarUtil.setSysNavigationColor(this, Color.parseColor("#141d26"));

        binding.cbAnim.setOnCheckedChangeListener(this);
        binding.cbBg.setOnCheckedChangeListener(this);
        binding.cbIcon.setOnCheckedChangeListener(this);
        binding.more.setOnClickListener(v -> {
            createTopRightMenu();
            mTopRightMenu.showAsDropDown(binding.more, -225, -20);
        });
    }

    private void createTopRightMenu() {
        mTopRightMenu = new TopRightMenu(this);
        List<MenuItem> menuItems = new ArrayList<>();
        menuItems.add(new MenuItem(R.mipmap.multichat, "发起多人聊天"));
        menuItems.add(new MenuItem(R.mipmap.addmember, "加好友"));
        menuItems.add(new MenuItem(R.mipmap.qr_scan, "扫一扫"));
        mTopRightMenu
                .setHeight(480)//默认高度480
                .setWidth(320)//默认宽度wrap_content
                .showIcon(showIcon)//显示菜单图标，默认为true
                .dimBackground(dimBg)//背景变暗，默认为true
                .needAnimationStyle(needAnim)//显示动画，默认为true
                .setAnimationStyle(R.style.TRM_ANIM_STYLE)  //默认为R.style.TRM_ANIM_STYLE
                .addMenuList(menuItems)
                .addMenuItem(new MenuItem(R.mipmap.facetoface, "面对面快传"))
                .addMenuItem(new MenuItem(R.mipmap.pay, "付款"))
                .setOnMenuItemClickListener(new TopRightMenu.OnMenuItemClickListener() {
                    @Override
                    public void onMenuItemClick(int position) {
                        Toast.makeText(TopRightMenuActivity.this, "点击菜单:" + position, Toast.LENGTH_SHORT).show();
                    }
                });
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
            case R.id.cb_anim:
                needAnim = isChecked;
                break;
            case R.id.cb_bg:
                dimBg = isChecked;
                break;
            case R.id.cb_icon:
                showIcon = isChecked;
                break;
        }
    }
}
